<div class="tab-pane in active" id="baseTab">
    <if condition="$rows">
        <foreach name="rows" item="row">
            <div>
                <div class="form-group">
                    <label class="control-label col-sm-2">航班号:</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="air_code[]" value="{$row.air_code}" placeholder="请填写航班号" />
                    </div>
                    <if condition="$key gt 0">
                        <button type="button" class="btn btn-primary" style="margin-left: 10px;" onclick="delName(this)">删除</button>
                    </if>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-2">始发地:</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="origin[]" value="{$row.origin}" placeholder="请填写始发地" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-2">目的地:</label>
                    <div class="col-sm-8">
                        <input class="form-control" name="destination[]" value="{$row.destination}" placeholder="请填写目的地" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-2">出发日期:</label>
                    <div class="col-sm-8">
                        <div class="input-group date" id="depart_date_num">
                            <input type='text' value="<if condition="$row['depart_date']">{$row.depart_date|date="Y-m-d H:i",###}</if>" name="depart_date[]" class="form-control " data-date-format="yyyy-mm-dd hh:ii" />
                            <div class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-2">到达日期:</label>
                    <div class="col-sm-8">
                        <div class="input-group date" id="reach_date_num">
                            <input type='text' value="<if condition="$row['depart_date']">{$row.reach_date|date="Y-m-d H:i",###}</if>" name="reach_date[]" class="form-control " data-date-format="yyyy-mm-dd hh:ii" />
                            <div class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </div>
                        </div>
                    </div>
                </div>
                <hr />
            </div>
        </foreach>
    <else/>
        <div>
            <div class="form-group">
                <label class="control-label col-sm-2">航班号:</label>
                <div class="col-sm-8">
                    <input class="form-control" name="air_code[]" value="" placeholder="请填写航班号" />
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">始发地:</label>
                <div class="col-sm-8">
                    <input class="form-control" name="origin[]" value="" placeholder="请填写始发地" />
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">目的地:</label>
                <div class="col-sm-8">
                    <input class="form-control" name="destination[]" value="" placeholder="请填写目的地" />
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">出发日期:</label>
                <div class="col-sm-8">
                    <div class="input-group date" id="depart_date_num">
                        <input type='text' value="" name="depart_date[]" class="form-control " data-date-format="yyyy-mm-dd hh:ii" />
                        <div class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">到达日期:</label>
                <div class="col-sm-8">
                    <div class="input-group date" id="reach_date_num">
                        <input type='text' value="" name="reach_date[]" class="form-control " data-date-format="yyyy-mm-dd hh:ii" />
                        <div class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </div>
                    </div>
                </div>
            </div>
            <hr />
        </div>
    </if>

    <button type="button" id="btn_prop" class="btn btn-primary pull-right">添加途经地</button>
</div>

<script type="text/javascript">

    $(function () {
        $("#btn_prop").bind("click",addName);
        changeItem();
    });

    function addName() {
        $("#btn_prop").before($("#prop_template").html());
        changeItem();
    }

    function delName(obj) {
        $(obj).parent().parent().remove();
        changeItem();
    }

    function changeItem() {
        var $divs = $("#baseTab").children("div");
        var len = $divs.length;
        for(var i=0;i<len;i++) {
            var departDateId = "depart_date_"+i;
            var reachDateId = "reach_date_"+i;
            $divs.eq(i).find("[id^='depart_date_']").attr("id",departDateId);
            $divs.eq(i).find("[id^='reach_date_']").attr("id",reachDateId);
            $("#"+departDateId).datetimepicker({
                format: "yyyy-mm-dd hh:ii",
                language: "ch",
                pickDate: true,
                pickTime: false,
                autoclose: true,
                minView: 0
            }).on('hide',function(e) {
                var bv = $('#air-form').data('bootstrapValidator');
                if(bv){
                    bv.updateStatus('depart_date[]', 'NOT_VALIDATED',null).validateField('depart_date[]');
                }
            });
            $("#"+reachDateId).datetimepicker({
                format: "yyyy-mm-dd hh:ii",
                language: "ch",
                pickDate: true,
                pickTime: false,
                autoclose: true,
                minView: 0
            }).on('hide',function(e) {
                var bv = $('#air-form').data('bootstrapValidator');
                if(bv){
                    bv.updateStatus('reach_date[]', 'NOT_VALIDATED',null).validateField('reach_date[]');
                }
            });
        }
    }
</script>